package com.kolakcc.loljclient.controller;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.SwingWorker;

import com.gvaneyck.rtmp.TypedObject;
import com.kolakcc.loljclient.StartupClass;
import com.kolakcc.loljclient.model.Champion;
import com.kolakcc.loljclient.model.swing.TeamListModel;
import com.kolakcc.loljclient.view.ChampionSelectView;
import com.kolakcc.loljclient.view.ui.ChampionBox;

public class ChampionSelectController extends KolaController implements MouseListener {
	ChampionSelectView view;
	protected SwingWorker<Void, Champion> championListWorker;
	ArrayList<Champion> champions;
	ChampionsController championsController;
	
	public ChampionSelectController(TeamListModel team1, TeamListModel team2) {
		championsController = new ChampionsController(this);
		this.view = new ChampionSelectView();
		for (Component uncastedComponent : championsController.view.championsPanel.getComponents()) {
			ChampionBox cb = (ChampionBox) uncastedComponent;
			cb.addMouseListener(this);
		}
		this.view.add(championsController.view.championsPanel,BorderLayout.CENTER);
		this.view.team1List.setModel(team1);
		this.view.team2List.setModel(team2);
	}
	@Override
	public void mouseClicked(MouseEvent e) {
		if (e.getClickCount() == 1) {
			ChampionBox box = (ChampionBox) e.getSource();
			try {
				int id = StartupClass.Client.invoke("gameService",
						"selectChampion", new Object[] { box.champion.getID() });
				TypedObject result = StartupClass.Client.getResult(id).getTO("data");
				System.out.println(result);
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	@Override
	public void mousePressed(MouseEvent e) {
	}
	@Override
	public void mouseReleased(MouseEvent e) {

	}
	@Override
	public void mouseEntered(MouseEvent e) {

	}
	@Override
	public void mouseExited(MouseEvent e) {
	}
}
